package com.lhy.ltss.dao;

import com.lhy.ltss.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @description:
 * @author: 李汇远
 */
public interface UserDao {

    @Select("select * from user where username = #{username}")
    User get(String username);

    // 获取用户列表，分页，条件查询（右边模糊匹配）
    @Select("select * from user where username like #{username} limit #{start},10 ")
    List<User> getUsers(@Param("username") String username, @Param("start") Integer start);

    @Select("select count(*) from user where username like #{username}")
    int countUsers(@Param("username") String username);


    @Update("update user set name=#{name},tel=#{tel} where username=#{username}")
    int update(@Param("name") String name, @Param("tel") String tel, @Param("username") String username);

    @Update("update user set password=#{password} where username=#{username} and password=#{oldPwd}")
    int updateUserPwd(@Param("password") String newPwd, @Param("oldPwd") String oldPwd, @Param("username") String username);

    // 修改密码
    @Update("update user set password=#{password} where username=#{username}")
    int updateUserPwd2(@Param("password") String password,@Param("username") String username);

    @Insert("insert into user(username,password,name,tel,role) values(#{username},#{password},#{name},#{tel},#{role})")
    int addUser(User user);
}
